<?php if(!class_exists("View", false)) exit("no direct access allowed");?><style>
    .thWidth {
    width: 150px !important;
}
.text-middle {
    vertical-align: middle!important;
}
.text-right {
    text-align: right;
}
.checkbox-right {
    padding-left: 0px !important;
}
.checkbox-primary, .radio-primary {
    position: relative;
    display: block;
    vertical-align: middle;
}
.checkbox-inline, .radio-inline {
    position: relative;
    display: inline-block;
    padding-left: 20px;
    margin-bottom: 0;
    font-weight: 400;
    vertical-align: middle;
    cursor: pointer;
}
.checkbox input[type=checkbox], .checkbox-inline input[type=checkbox], .radio input[type=radio], .radio-inline input[type=radio] {
    position: absolute;
    margin-top: 3px;
    margin-top: 4px\9;
    margin-left: -20px;
}
.checkbox-primary>input, .radio-primary>input {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 3;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
}
.checkbox-primary>label, .radio-primary>label {
    display: block;
    height: 20px;
    padding-left: 30px;
    margin: 0;
    font-weight: 400;
    line-height: 20px;
    cursor: pointer;
}
.group-item {
    display: block;
    width: 220px;
    float: left;
    font-size: 14px;
}
</style>
<main id="main" class="in">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12">
                <div class="panel">
                    <div class="panel-heading">
                        <div class="title">  
                          浏览权限-<?php echo htmlspecialchars($app['appName'], ENT_QUOTES, "UTF-8"); ?>-所有权限模块                          
                        </div>
                        
                    </div>
                    <div class="panel-body">  
                      <table class="table table-hover table-striped table-bordered privlist">
                        <thead>
                            <tr class="text-center">
                              <th class="thWidth">模块</th>
                              <th colspan="2">方法</th>
                            </tr>
                          </thead>
                        <tbody>
                          <?php if(!empty($apps)){ $_foreach_v_counter = 0; $_foreach_v_total = count($apps);?><?php foreach( $apps as $k => $v ) : ?><?php $_foreach_v_index = $_foreach_v_counter;$_foreach_v_iteration = $_foreach_v_counter + 1;$_foreach_v_first = ($_foreach_v_counter == 0);$_foreach_v_last = ($_foreach_v_counter == $_foreach_v_total - 1);$_foreach_v_counter++;?>
                            <tr>
                                <th class="text-middle text-right thWidth">
                                    <div class="checkbox-primary checkbox-inline checkbox-right check-all">                                        
                                    <input type="checkbox" id="allChecker<?php echo htmlspecialchars($v['module'], ENT_QUOTES, "UTF-8"); ?>" <?php if(!empty($acl)){ $_foreach_v2_counter = 0; $_foreach_v2_total = count($acl);?><?php foreach( $acl as $k2 => $v2 ) : ?><?php $_foreach_v2_index = $_foreach_v2_counter;$_foreach_v2_iteration = $_foreach_v2_counter + 1;$_foreach_v2_first = ($_foreach_v2_counter == 0);$_foreach_v2_last = ($_foreach_v2_counter == $_foreach_v2_total - 1);$_foreach_v2_counter++;?><?php if ($v2['id'] == $v['id']) : ?>checked="checked"<?php endif; ?><?php endforeach; }?> onchange="chkchilds(this)" value="<?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>" data-id="<?php echo htmlspecialchars($v['module'], ENT_QUOTES, "UTF-8"); ?>" >
                                    <label class="text-right" for="allCheckermy<?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>"><?php echo htmlspecialchars($v['moduleName'], ENT_QUOTES, "UTF-8"); ?></label>
                                    </div>
                                </th>
                                <td>
                                    <?php if(!empty($v['childs'])){ $_foreach_v1_counter = 0; $_foreach_v1_total = count($v['childs']);?><?php foreach( $v['childs'] as $k1 => $v1 ) : ?><?php $_foreach_v1_index = $_foreach_v1_counter;$_foreach_v1_iteration = $_foreach_v1_counter + 1;$_foreach_v1_first = ($_foreach_v1_counter == 0);$_foreach_v1_last = ($_foreach_v1_counter == $_foreach_v1_total - 1);$_foreach_v1_counter++;?>
                                    <div class="group-item">
                                        <div class="checkbox-primary checkbox-inline">
                                            <input type="checkbox" name="actions[<?php echo htmlspecialchars($v1['module'], ENT_QUOTES, "UTF-8"); ?>]" <?php if(!empty($acl)){ $_foreach_v2_counter = 0; $_foreach_v2_total = count($acl);?><?php foreach( $acl as $k2 => $v2 ) : ?><?php $_foreach_v2_index = $_foreach_v2_counter;$_foreach_v2_iteration = $_foreach_v2_counter + 1;$_foreach_v2_first = ($_foreach_v2_counter == 0);$_foreach_v2_last = ($_foreach_v2_counter == $_foreach_v2_total - 1);$_foreach_v2_counter++;?><?php if ($v2['id'] == $v1['id']) : ?>checked="checked"<?php endif; ?><?php endforeach; }?> onchange="chkparents(this)" data-id="<?php echo htmlspecialchars($v1['module'], ENT_QUOTES, "UTF-8"); ?>" value="<?php echo htmlspecialchars($v1['id'], ENT_QUOTES, "UTF-8"); ?>" id="actions[<?php echo htmlspecialchars($v1['module'], ENT_QUOTES, "UTF-8"); ?>]<?php echo htmlspecialchars($v1['method'], ENT_QUOTES, "UTF-8"); ?>"> 
                                            <label for="actions[<?php echo htmlspecialchars($v1['module'], ENT_QUOTES, "UTF-8"); ?>]<?php echo htmlspecialchars($v1['method'], ENT_QUOTES, "UTF-8"); ?>"><?php echo htmlspecialchars($v1['methodName'], ENT_QUOTES, "UTF-8"); ?></label>
                                        </div>          
                                    </div>
                                    <?php endforeach; }?>
                                </td>
                            </tr>
                          <?php endforeach; }?>
                          <tr>
                            <th class="text-right">
                              <div class="checkbox-primary checkbox-inline checkbox-right check-all">
                                <input type="checkbox" id="allChecker" onchange="chkall(this)">
                                <label class="text-right" for="allChecker">全选</label>
                              </div>
                            </th>
                            <td class="form-actions" colspan="2">
                               <button type="button" id="submit" class="btn btn-wide btn-primary privaddbtn" onclick="setNoChecked()" data-loading="稍候...">保存</button>          <a href="javascript:history.go(-1);" class="btn btn-back btn-wide">返回</a>          <input type="hidden" name="noChecked" id="noChecked" value="">
                            </td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <input type="hidden" value="<?php echo htmlspecialchars($appid, ENT_QUOTES, "UTF-8"); ?>" id="appid" />
            <input type="hidden" value="<?php echo htmlspecialchars($groupid, ENT_QUOTES, "UTF-8"); ?>" id="groupid" />
    <script src="http://p1.renbenzhihui.com/zui/js/all.js"></script>
          <script src="/i/js/util.js"></script>
          <script src="http://p1.renbenzhihui.com/zui/lib/datatable/zui.datatable.min.js"></script>
          <script> 
            function chkchilds(obj){
                var id = $(obj).attr('data-id');
                if ($(obj).prop("checked")) {                    
                    $('input[name="actions['+id+']"]').attr("checked", 'checked');
                } else {
                    $('input[name="actions['+id+']"]').attr("checked", false);
                }
            }
            function chkparents(obj){
                var id = $(obj).attr('data-id');
                if ($(obj).prop("checked")) {                    
                    $('#allChecker'+id+'').attr("checked", 'checked');
                } else {
                    var count =0;
                    $('input[name="actions['+id+']"]:checked').each(function(){
                        count++;
                    });
                    if(count==0){
                        $('#allChecker'+id+'').attr("checked", false);
                    }
                }
            }
            function chkall(obj){
                if ($(obj).prop("checked")) {                    
                    $('input[type="checkbox"]').attr("checked", 'checked');
                } else {
                    $('input[type="checkbox"]').attr("checked", false);
                }
            }
            function del(id){
                $.get('<?php echo url(array('c'=>"System", 'a'=>"GroupDel", 'id'=>"", ));?>'+id,function(data){
                  data = JSON.parse(data);
                    if(data.code/1 == 1){
                      location.reload();
                    }else{
                      new $.zui.Messager(data.msg, {
                                  type: 'danger',
                                  icon: 'exclamation-sign',
                                  placement: 'center' // 定义显示位置
                              }).show();
                    }
                });
            } 
            function setNoChecked()
            {
                var noCheckValue = '';
                $(':checkbox').each(function(){
                    if(!$(this).prop('checked') && $(this).next('span').attr('id') != undefined) noCheckValue = noCheckValue + ',' + $(this).next('span').attr('id');
                })
                $('#noChecked').val(noCheckValue);
            }
    
            $(function(){
                $('.privadd').on('click',function(){
                    $('#editModal').modal({
                    name:'editModal',
                    backdrop:true,
                    keyboard:true
                    })
                }); 
                $('.privaddbtn').on('click',function(){
                    var appid = Utils.paseData($('#appid').val());
                    var groupid = Utils.paseData($('#groupid').val());
                    var strs = '';
                    $('input[type="checkbox"]:checked').each(function(){
                        var id = Utils.paseData($(this).val());
                        if(id != ''){
                            strs += id+',';
                        }
                    });
                    strs = strs.substring(0,strs.length-1);
                    strs = strs.replace(',on', '');
                    if(groupid != '' && strs != ''){
                        $.post('<?php echo url(array('c'=>"System", 'a'=>"GroupprivUp", ));?>',{groupid:groupid,acl:strs},function(data){
                            data = JSON.parse(data);
                            if(data.code/1 == 1){
                                new $.zui.Messager(data.msg, {
                                        type: 'info',
                                        icon: 'exclamation-sign',
                                        placement: 'center' // 定义显示位置
                                }).show();
                            }else{
                                new $.zui.Messager(data.msg, {
                                        type: 'danger',
                                        icon: 'exclamation-sign',
                                        placement: 'center' // 定义显示位置
                                }).show();
                            }
                        });
                    }else{
                        new $.zui.Messager('分组名称为必填项', {
                                        type: 'danger',
                                        icon: 'exclamation-sign',
                                        placement: 'center' // 定义显示位置
                                    }).show();
                        }
                    });
            });
            </script>
  </main>